
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 06/06/2012 23:45:34
-- Generated from EDMX file: D:\Users\Matte\Documents\Visual Studio 2010\Projects\SviluppoDistinta\SviluppoDistinta.Library\MainDataModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [SviluppoDistinta];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_OrdineArticolo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrdiniSet] DROP CONSTRAINT [FK_OrdineArticolo];
GO
IF OBJECT_ID(N'[dbo].[FK_ClienteOrdine]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrdiniSet] DROP CONSTRAINT [FK_ClienteOrdine];
GO
IF OBJECT_ID(N'[dbo].[FK_OrdineColore]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ColoriSet] DROP CONSTRAINT [FK_OrdineColore];
GO
IF OBJECT_ID(N'[dbo].[FK_OrdineTaglia]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TaglieSet] DROP CONSTRAINT [FK_OrdineTaglia];
GO
IF OBJECT_ID(N'[dbo].[FK_ArticoloParte]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PartiSet] DROP CONSTRAINT [FK_ArticoloParte];
GO
IF OBJECT_ID(N'[dbo].[FK_ColorePacco]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PaccoSet] DROP CONSTRAINT [FK_ColorePacco];
GO
IF OBJECT_ID(N'[dbo].[FK_PartePacco]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PaccoSet] DROP CONSTRAINT [FK_PartePacco];
GO
IF OBJECT_ID(N'[dbo].[FK_TagliaPacco]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PaccoSet] DROP CONSTRAINT [FK_TagliaPacco];
GO
IF OBJECT_ID(N'[dbo].[FK_ArticoloPacco]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PaccoSet] DROP CONSTRAINT [FK_ArticoloPacco];
GO
IF OBJECT_ID(N'[dbo].[FK_OrdinePacco]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PaccoSet] DROP CONSTRAINT [FK_OrdinePacco];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[OrdiniSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrdiniSet];
GO
IF OBJECT_ID(N'[dbo].[ArticoliSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ArticoliSet];
GO
IF OBJECT_ID(N'[dbo].[ClientiSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ClientiSet];
GO
IF OBJECT_ID(N'[dbo].[ColoriSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ColoriSet];
GO
IF OBJECT_ID(N'[dbo].[TaglieSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TaglieSet];
GO
IF OBJECT_ID(N'[dbo].[PartiSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PartiSet];
GO
IF OBJECT_ID(N'[dbo].[PaccoSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PaccoSet];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'OrdiniSet'
CREATE TABLE [dbo].[OrdiniSet] (
    [IDOrdine] int IDENTITY(1,1) NOT NULL,
    [CapiPerGruppo] int  NOT NULL,
    [Bolla] nvarchar(max)  NOT NULL,
    [Articolo_IDArticolo] int  NOT NULL,
    [Cliente_IDCliente] int  NOT NULL
);
GO

-- Creating table 'ArticoliSet'
CREATE TABLE [dbo].[ArticoliSet] (
    [IDArticolo] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'ClientiSet'
CREATE TABLE [dbo].[ClientiSet] (
    [IDCliente] int IDENTITY(1,1) NOT NULL
);
GO

-- Creating table 'ColoriSet'
CREATE TABLE [dbo].[ColoriSet] (
    [IDColore] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(max)  NOT NULL,
    [Ordine_IDOrdine] int  NOT NULL
);
GO

-- Creating table 'TaglieSet'
CREATE TABLE [dbo].[TaglieSet] (
    [IDTaglia] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(max)  NOT NULL,
    [RS15] nvarchar(max)  NOT NULL,
    [Ordine_IDOrdine] int  NOT NULL
);
GO

-- Creating table 'PartiSet'
CREATE TABLE [dbo].[PartiSet] (
    [IDParte] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(max)  NOT NULL,
    [NumeroNecessario] int  NOT NULL,
    [PerNumeroCapi] int  NOT NULL,
    [GruppiCapiPerPacco] int  NOT NULL,
    [RS16] nvarchar(max)  NOT NULL,
    [Articolo_IDArticolo] int  NOT NULL
);
GO

-- Creating table 'PaccoSet'
CREATE TABLE [dbo].[PaccoSet] (
    [IDPacco] int IDENTITY(1,1) NOT NULL,
    [NumeroPezzi] int  NOT NULL,
    [PaccoNumero] int  NOT NULL,
    [XRif] int  NOT NULL,
    [YRif] int  NOT NULL,
    [Colore_IDColore] int  NOT NULL,
    [Parte_IDParte] int  NOT NULL,
    [Taglia_IDTaglia] int  NOT NULL,
    [Articolo_IDArticolo] int  NOT NULL,
    [Ordine_IDOrdine] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [IDOrdine] in table 'OrdiniSet'
ALTER TABLE [dbo].[OrdiniSet]
ADD CONSTRAINT [PK_OrdiniSet]
    PRIMARY KEY CLUSTERED ([IDOrdine] ASC);
GO

-- Creating primary key on [IDArticolo] in table 'ArticoliSet'
ALTER TABLE [dbo].[ArticoliSet]
ADD CONSTRAINT [PK_ArticoliSet]
    PRIMARY KEY CLUSTERED ([IDArticolo] ASC);
GO

-- Creating primary key on [IDCliente] in table 'ClientiSet'
ALTER TABLE [dbo].[ClientiSet]
ADD CONSTRAINT [PK_ClientiSet]
    PRIMARY KEY CLUSTERED ([IDCliente] ASC);
GO

-- Creating primary key on [IDColore] in table 'ColoriSet'
ALTER TABLE [dbo].[ColoriSet]
ADD CONSTRAINT [PK_ColoriSet]
    PRIMARY KEY CLUSTERED ([IDColore] ASC);
GO

-- Creating primary key on [IDTaglia] in table 'TaglieSet'
ALTER TABLE [dbo].[TaglieSet]
ADD CONSTRAINT [PK_TaglieSet]
    PRIMARY KEY CLUSTERED ([IDTaglia] ASC);
GO

-- Creating primary key on [IDParte] in table 'PartiSet'
ALTER TABLE [dbo].[PartiSet]
ADD CONSTRAINT [PK_PartiSet]
    PRIMARY KEY CLUSTERED ([IDParte] ASC);
GO

-- Creating primary key on [IDPacco] in table 'PaccoSet'
ALTER TABLE [dbo].[PaccoSet]
ADD CONSTRAINT [PK_PaccoSet]
    PRIMARY KEY CLUSTERED ([IDPacco] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Articolo_IDArticolo] in table 'OrdiniSet'
ALTER TABLE [dbo].[OrdiniSet]
ADD CONSTRAINT [FK_OrdineArticolo]
    FOREIGN KEY ([Articolo_IDArticolo])
    REFERENCES [dbo].[ArticoliSet]
        ([IDArticolo])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrdineArticolo'
CREATE INDEX [IX_FK_OrdineArticolo]
ON [dbo].[OrdiniSet]
    ([Articolo_IDArticolo]);
GO

-- Creating foreign key on [Cliente_IDCliente] in table 'OrdiniSet'
ALTER TABLE [dbo].[OrdiniSet]
ADD CONSTRAINT [FK_ClienteOrdine]
    FOREIGN KEY ([Cliente_IDCliente])
    REFERENCES [dbo].[ClientiSet]
        ([IDCliente])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ClienteOrdine'
CREATE INDEX [IX_FK_ClienteOrdine]
ON [dbo].[OrdiniSet]
    ([Cliente_IDCliente]);
GO

-- Creating foreign key on [Ordine_IDOrdine] in table 'ColoriSet'
ALTER TABLE [dbo].[ColoriSet]
ADD CONSTRAINT [FK_OrdineColore]
    FOREIGN KEY ([Ordine_IDOrdine])
    REFERENCES [dbo].[OrdiniSet]
        ([IDOrdine])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrdineColore'
CREATE INDEX [IX_FK_OrdineColore]
ON [dbo].[ColoriSet]
    ([Ordine_IDOrdine]);
GO

-- Creating foreign key on [Ordine_IDOrdine] in table 'TaglieSet'
ALTER TABLE [dbo].[TaglieSet]
ADD CONSTRAINT [FK_OrdineTaglia]
    FOREIGN KEY ([Ordine_IDOrdine])
    REFERENCES [dbo].[OrdiniSet]
        ([IDOrdine])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrdineTaglia'
CREATE INDEX [IX_FK_OrdineTaglia]
ON [dbo].[TaglieSet]
    ([Ordine_IDOrdine]);
GO

-- Creating foreign key on [Articolo_IDArticolo] in table 'PartiSet'
ALTER TABLE [dbo].[PartiSet]
ADD CONSTRAINT [FK_ArticoloParte]
    FOREIGN KEY ([Articolo_IDArticolo])
    REFERENCES [dbo].[ArticoliSet]
        ([IDArticolo])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ArticoloParte'
CREATE INDEX [IX_FK_ArticoloParte]
ON [dbo].[PartiSet]
    ([Articolo_IDArticolo]);
GO

-- Creating foreign key on [Colore_IDColore] in table 'PaccoSet'
ALTER TABLE [dbo].[PaccoSet]
ADD CONSTRAINT [FK_ColorePacco]
    FOREIGN KEY ([Colore_IDColore])
    REFERENCES [dbo].[ColoriSet]
        ([IDColore])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ColorePacco'
CREATE INDEX [IX_FK_ColorePacco]
ON [dbo].[PaccoSet]
    ([Colore_IDColore]);
GO

-- Creating foreign key on [Parte_IDParte] in table 'PaccoSet'
ALTER TABLE [dbo].[PaccoSet]
ADD CONSTRAINT [FK_PartePacco]
    FOREIGN KEY ([Parte_IDParte])
    REFERENCES [dbo].[PartiSet]
        ([IDParte])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PartePacco'
CREATE INDEX [IX_FK_PartePacco]
ON [dbo].[PaccoSet]
    ([Parte_IDParte]);
GO

-- Creating foreign key on [Taglia_IDTaglia] in table 'PaccoSet'
ALTER TABLE [dbo].[PaccoSet]
ADD CONSTRAINT [FK_TagliaPacco]
    FOREIGN KEY ([Taglia_IDTaglia])
    REFERENCES [dbo].[TaglieSet]
        ([IDTaglia])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TagliaPacco'
CREATE INDEX [IX_FK_TagliaPacco]
ON [dbo].[PaccoSet]
    ([Taglia_IDTaglia]);
GO

-- Creating foreign key on [Articolo_IDArticolo] in table 'PaccoSet'
ALTER TABLE [dbo].[PaccoSet]
ADD CONSTRAINT [FK_ArticoloPacco]
    FOREIGN KEY ([Articolo_IDArticolo])
    REFERENCES [dbo].[ArticoliSet]
        ([IDArticolo])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ArticoloPacco'
CREATE INDEX [IX_FK_ArticoloPacco]
ON [dbo].[PaccoSet]
    ([Articolo_IDArticolo]);
GO

-- Creating foreign key on [Ordine_IDOrdine] in table 'PaccoSet'
ALTER TABLE [dbo].[PaccoSet]
ADD CONSTRAINT [FK_OrdinePacco]
    FOREIGN KEY ([Ordine_IDOrdine])
    REFERENCES [dbo].[OrdiniSet]
        ([IDOrdine])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrdinePacco'
CREATE INDEX [IX_FK_OrdinePacco]
ON [dbo].[PaccoSet]
    ([Ordine_IDOrdine]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------